<?php
namespace app\admin\controller;

use think\Controller;
use think\Request;
use think\Session;
class Type extends Controller 
{

    /**
     *  分页
     */

    public function show()
    {
         $page = Request::instance()->post('page',1);
         $size = Request::instance()->post('size',10);

         $data = model('GoodsType')->getAll($size,$page);

         // $data['prev'] = $page - 1 < 1 ? 1 : $page - 1;
         // $data['next'] = $page + 1 > $data['last_page'] ? $data['last_page'] : $page + 1;
          
        
        return view( 'show',['data'=> $data]);
    }


    /**
     * 添加
     */

    public function add()
    {
        if(!Request::instance()->post())
        {
            $data['type'] = model('GoodsType')->getAll();
            return view('add',['data'=>$data]);
        }

        $data = Request::instance()->post();

        
        $timeNow = date('Y-m-d H:i:s',time());
        $userId = 1;
        $data['status'] = 1;
        $data['create_user'] = $userId;
        $data['create_time'] = $timeNow;
        $data['update_user'] = $userId;
        $data['update_time'] = $timeNow;

        //调用模型层添加
        $res = model('GoodsType')->addOne($data);
      
        if(!$res)
        {
            $this->redirect('Type/add');
        }
        $this->redirect('Type/show');
     }

}
